package iodemo;

import java.io.*;

public class BufferedIO
{
    public static void main (String[] args)
    {
        long time1 = System.currentTimeMillis();
    
        copyFile("F:/MC_MOD/new.txt", "D:/NoYouKnow.txt");
    
        long time2 = System.currentTimeMillis();
    
        System.out.println(time2 - time1);
    }
    
    /**
     *
     * @param source       源文件
     * @param destination  目标文件
     */
    public static void copyFile(String source, String destination)
    {
        try(FileInputStream fileInputStream = new FileInputStream(source);
            FileOutputStream fileOutputStream = new FileOutputStream(destination);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream))
        {
            int temp = 0;
            
            while((temp = bufferedInputStream.read()) != -1)
            {
                bufferedOutputStream.write(temp);
            }
            
            bufferedOutputStream.flush();
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }
}
